package com.somnus.androidkotlindemo.databinding;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.view.ViewGroup;

import com.android.databinding.library.baseAdapters.BR;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

public abstract class EasyBindQuickAdapter<T> extends BaseQuickAdapter<T, BindingViewHolder> {

    public EasyBindQuickAdapter(int layoutResId, List<T> data) {
        super(layoutResId, data);
    }

    public EasyBindQuickAdapter(List<T> data) {
        super(data);
    }

    public EasyBindQuickAdapter(int layoutResId) {
        super(layoutResId);
    }

//    @Override
//    protected View getItemView(int layoutResId, ViewGroup parent) {
//        View view = mLayoutInflater.inflate(layoutResId, parent, false);
//        return view;
//    }

    @Override
    protected BindingViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        ViewDataBinding binding = DataBindingUtil.inflate(mLayoutInflater, mLayoutResId, parent, false);
        return new BindingViewHolder<>(binding);
    }

    @Override
    protected void convert(BindingViewHolder holder, T item) {
        easyConvert(holder, item);
        ViewDataBinding binding = holder.getBinding();
        binding.setVariable(BR.item, item);
        binding.executePendingBindings();

    }

    protected abstract void easyConvert(BindingViewHolder holder, T item);
}
